package com.qhyt.utils;

import org.apache.poi.ss.usermodel.Workbook;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

/**
 * @author jie
 * @date 2021/3/5 -15:43
 */
public class ExportUtils {

    /**
     * 导出io流
     *
     * @param filename 文件名
     */
    public static void ioExport(HttpServletResponse response, Workbook workbook, String filename) {
        try {
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
            workbook.write(response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
